<?php namespace Home\Controller; 

use Hdphp\Controller\Controller;
use Common\Model\Goods;

//测试控制器
class IndexController extends Controller{

	//构造函数
	public function __init()
	{
	}
	
    //首页
    public function index(){
//		p($_SESSION);
		
		
		//分配商品信息-查询商品表
		$goodsModel = new Goods();
		
		//1.当日精选
		$today = $goodsModel->orderBy('gid','DESC')->limit(4)->get();
		foreach ($today as $k => $v) {
			$today[$k]['gname'] = substr($v['gname'],0,18);
		}
		View::with('today',$today);
		
		//2.定制推荐
		$order = $goodsModel->orderBy('shopprice','DESC')->limit(4)->get();
		foreach ($order as $k => $v) {
			$order[$k]['gname'] = substr($v['gname'],0,18);
		}
		View::with('order',$order);
		
		//3.设计精选
		$news = $goodsModel->orderBy('time','ASC')->limit(4)->get();
		foreach ($news as $k => $v) {
			$news[$k]['gname'] = substr($v['gname'],0,18);
		}
		View::with('news',$news);
		
		//4.闪购
		$hot = $goodsModel->orderBy('click','DESC')->limit(4)->get();
		foreach ($hot as $k => $v) {
			$hot[$k]['gname'] = substr($v['gname'],0,18);
		}
		View::with('hot',$hot);
		
		//5.创意画报
		$ideas = $goodsModel->orderBy('stock','DESC')->limit(4)->get();
		foreach ($ideas as $k => $v) {
			$ideas[$k]['gname'] = substr($v['gname'],0,18);
		}
		View::with('ideas',$ideas);
		
       	View::make();
    }
}
